﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Sequence
{
    /// <summary>
    /// Interaction logic for ProductList.xaml
    /// </summary>
    public partial class DialogProductList : Window
    {
        private SalesManagerEntities _context = new SalesManagerEntities();
        private CollectionViewSource _productsViewSource;
        private int _ownerID;
        public int ProductID = -1;

        public DialogProductList(int ownerID)
        {
            _ownerID = ownerID;
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            _productsViewSource = (CollectionViewSource)FindResource("Products");
            _productsViewSource.Source = from c in _context.tblProduct
                                         where c.OwnerID == _ownerID
                                         select c;
        }

        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            ProductID = ((tblProduct)_productsViewSource.View.CurrentItem).ProductID;
            this.DialogResult = true;
            this.Close();
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
            this.Close();
        }

        private void lstProducts_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            btnOK_Click(sender, null);
        }
    }
}
